#include "gui_pconfig.h"
#include "custom.h"

int16_t g_set_reg[10];

const char* disp_week[3][7] = 
{
    {"日", "一", "二", "三","四","五","六"},
    {"Sun.", "Mon.", "Tue.", "Wed.","Thu.","Fri.","Sat."},
    {"Nd.", "Pon.", "Wt.", "Śr.","Czw.","Pt.","Sob."},
};
const char* disp_active[3][2] = 
{
    {"禁用","启用"},
    {"Disable","Enable"},
    {"Wyłączać","Umożliwiać"},
};
const char* string_fault[3] = {"故障", "Fault","Błąd"};
const char* string_return[3] = {"返回主屏", "Return", "Wrócić"};
const char* string_comm_err[3] = {"线控器通讯故障!","Communication failure!","Awaria komunikacji kontrolera przewodowego!"};
const char* string_password_error[3] = {"密码错误", "wrong password!","Błędne hasło!"};
const char* string_no_err[3] = {"当前无故障!","No failure!","Obecnie bezawaryjny!"};

/*-----------screen_1-----------*/
const char* string_hum[3] = {"湿度", "Humidity", "Wilgotność"};
const char* string_env_temp[3] = {"室外温度", "Env.", "Środowisko"};
const char* string_pm25_temp[3][3] = 
{
    { "优", "良", "差"},
    { "Good", "Fair", "Bad"},
    { "Wybitny", "Dobry", "Różnica"},
};
const char* disp_menu_item[3][6] = 
{
    {"模式选择", "运行状态", "参数设置", "场景选择", "房间数据", "用户设置"},
    {"Mode", "Status", "Setting", "Scene", "Room set", "User set"},
    {"Tryb", "Stan", "Zakładać", "Sceneria", "Pokój", "System"},
};
const char* disp_work_mode_1[3][3] = 
{
    {"离家", "回家", "睡眠"},
    {"Leave", "Return", "Sleep"},
    {"Lewy", "Wrócić", "Spać"},
};
const char* disp_work_mode_2[3][3] = 
{
    {"离家模式", "回家模式", "睡眠模式"},
    {"Leave home mode", "Go home mode", "Sleep mode"},
    {"Tryb poza domem", "Tryb Wrócić domu", "Tryb spać"},
};
const char* disp_switch[3][2] = 
{
    {"已关机", "已开机"},
    {"OFF", "ON"},
    {"OFF", "ON"},
};

/*-----------screen_2-----------*/
const char* string_mode_enum[3][3] = { 
    {"制冷", "制热", "通风"},
    {"Cooling", "Heating", "FAN"},
    {"Chłodzenie", "grzanie", "FAN"}
};
const char* string_setting_fan[3][4] = { 
    {"自动", "低速", "中速", "高速"},
    {"Auto", "Low", "Middle", "High"},
    {"Auto", "Niski", "Średni", "Wysoki"}
};
const char* string_set_temp[3] = { "设定温度", "Temp. Set", "Temp. zakładać"};

/*-----------screen_3-----------*/
const char* string_fan_speed[3] = {"风速", "Fan speed", "Prędkość wiatru"};
const char* string_out_fan_temp[3] = {"出风温度", "Fan speed", "Wiatr temp."};
const char* disp_switch_time[3][2] = 
{
    {"开机时间", "关机时间"},
    {"Turn on time", "Turn off time"},
    {"Czas ON", "Czas OFF"},
};

/*-----------screen_4-----------*/
const char* disp_screen_4_item_1[3][7] = 
{
    {"茶室", "办公区", "展示厅", "门厅", "会客区", "餐厅", "办公室"},
    {"Kitchen", "Office 1", "Showroom", "Entrance", "Guest Room", "Dining Hall", "Office 2"},
    {"Herbaciarnia", "Biuro 1", "Salonu", "Foyer", "Recepcja", "Restauracja", "Biuro 2"},
};
const char* string_dew_point_temp[3] = {"露点", "Dew point", "Punkt rosy"};
const char* string_temp[3] = {"温度", "Temp.","Temp."};
const char* disp_screen_4_item_2[3][4] = 
{
    {"顶辐射", "露点控制", "节能", "锁定"},
    {"Top radiation", "Dew point ctrl", "ECO", "Lock"},
    {"Promieniowanie", "Kontrola punktu rosy", "ECO", "Zamek"},
};

/*-----------screen_5-----------*/
const char* disp_screen_5_item_1[3][5] = 
{
    {"设备", "新风机", "滤网数据", "茶室", "连接状态"},
    {"Device", "Fan", "Filter Data", "Kitchen", "Connection Status"},
    {"Sprzęt", "Fanów", "Filtr dane", "Herbaciarnia", "Stan połączyć"},
};
const char* disp_paging[3][2] = 
{
    {"上一页", "下一页"},
    {"Previous", "Next"},
    {"Poprzedni", "Następny"},
};
const char* string_status_param[3] = {"状态参数", "Status param", "Stan param"};

/*-----------screen_6-----------*/
const char* disp_screen_6_item_1[3][5] = 
{
    {"环境参数", "公共参数", "滤网数据", "茶室", "连接状态"},
    {"Environment", "Common", "Filter Data", "Kitchen", "Connection Status"},
    {"Środowisko param", "Wspólne param", "Filtr dane", "Herbaciarnia", "Stan połączyć"},
};
const char* string_set_param[3] = {"设置参数", "Set param", "Zakładać param"};

/*-----------screen_7-----------*/
const char* disp_screen_7_item_1[3][3] = 
{
    {"通用", "网络设置", "日期和时间"},
    {"General", "Internet", "Date & Time"},
    {"Ogólne", "Internet", "Data i Godzina"},
};
const char *disp_screen_7_language[3] = {"中文\n英文\n波兰", "Chinese\nEnglish\nPolish", "Chiński\nAngielski\nPolski"};




const disp_enum_t set_enum0[2] = {{0, {"禁用", "Disable", "Wyłączony"}}, {1, {"启用", "Enable", "Włączony"}}};
const disp_enum_t set_enum1[2] = {{0, {"热点", "AP","AP"}}, {1, {"快连", "Smart","Szybki"}}};
const disp_enum_t set_enum2[2] = {{0, {"节能", "ECO","ECO"}}, {1, {"常亮", "Always","Zawsze"}}};
const disp_enum_t set_enum3[1] = {{0, {"设置", "Setup","Ustalić"}}};
const disp_enum_t set_enum4[3] = {{0, {"中文","Chinese","Chiński"}},{1, {"英文","English","Angielski"}}, {2, {"波兰","Polish","Polski"}}};
const disp_enum_t set_enum5[2] = {{0, {"关", "OFF", "OFF"}} , {1, {"开", "ON", "ON"}}};
const disp_enum_t set_enum6[2] = {{0, {"℃", "℃", "℃"}} , {1, {"℉", "℉", "℉"}}};



const disp_ui_set_t disp_ui_set[] = {
    {(void *)0, {"系统时钟", "System Time"  ,"Data i godzina"    } , WORD_TYPE_RTCSET, &g_set_reg[0], 0, 1, (disp_enum_t *)set_enum3, 1},
    {(void *)0, {"记忆开关", "Power-off Memory","Pamięć trybu."  } , WORD_TYPE_ENUM ,  &g_UserSet.MemoryOn, 0, 1, (disp_enum_t *)set_enum0, 2},
    // {(void *)0, {"WIFI开关", "Wifi Enable" ,"Wifi Enable"           } , WORD_TYPE_ENUM ,  &g_UserSet.WifiEn, 0, 1, (disp_enum_t *)set_enum0, 2},
    {(void *)0, {"WIFI设置", "Wifi Setting" ,"Tryb WIFI"         } , WORD_TYPE_WIFI ,  &g_UserSet.WifiSet, 0, 1, (disp_enum_t *)set_enum1, 2},
    {(void *)0, {"按键声音", "Key Sound"    ,"Dźwięk przycisku"  } , WORD_TYPE_ENUM ,  &g_UserSet.BeepEn, 0, 1, (disp_enum_t *)set_enum0, 2},
    {(void *)0, {"故障声音", "Fault tone"   ,"Alarm dźwiękowy"   } , WORD_TYPE_ENUM ,  &g_UserSet.FaultTone, 0, 1, (disp_enum_t *)set_enum0, 2},
    {(void *)0, {"背光模式", "Back light"   ,"Wyświetlacz"       } , WORD_TYPE_ENUM ,  &g_UserSet.BlkMode, 0, 1, (disp_enum_t *)set_enum2, 2},
    {(void *)0, {"语言设置", "Language"     ,"Język"             } , WORD_TYPE_ENUM ,  &g_UserSet.Lauguage, 0, 2, (disp_enum_t *)set_enum4, 3},
    {(void *)0, {"复位设置", "Reset"        ,"Reset"             } , WORD_TYPE_RESET , &g_set_reg[0], 0, 0, (disp_enum_t *)set_enum3, 1},
    {(void *)0, {"温度单位", "temp. unit"   ,"Jednostki temp."   } , WORD_TYPE_RESET , &g_UserSet.unit, 0, 1, (disp_enum_t *)set_enum6, 2}
};

const disp_ui_word_t check0_ui_word[] = {
    {(void *)0, {"001. Online qty"          , "001. 在线数量"               , "001. Online qty"                 }, 400, 0, 16, 0, 1, WORD_TYPE_INT, NULL, ""},
};

const disp_ui_word_t seting0_ui_word[] = {//功能设置  
    {(void *)0, {"001. DHW Mode"           , "001. DHW Mode"          , "001. DHW Mode"          }, 800, 0, 16, 0, 1, WORD_TYPE_INT, NULL, ""},
    {(void *)0, {"002. Disinfection"       , "002. Disinfection"      , "002. Disinfection"      }, 801, 0, 16, 0, 1, WORD_TYPE_INT, NULL, ""},
    {(void *)0, {"003. DHW PRI"            , "003. DHW PRI"           , "003. DHW PRI"           }, 802, 0, 16, 0, 1, WORD_TYPE_INT, NULL, ""},
    {(void *)0, {"004. DHW Pump"           , "004. DHW Pump"          , "004. DHW Pump"          }, 803, 0, 16, 0, 1, WORD_TYPE_INT, NULL, ""},
    {(void *)0, {"005. DHW PRI Time"       , "005. DHW PRI Time"      , "005. DHW PRI Time"      }, 804, 0, 16, 0, 1, WORD_TYPE_INT, NULL, ""},
    {(void *)0, {"006. dT8_ON"             , "006. dT8_ON"            , "006. dT8_ON"            }, 805, 0, 16, 0, 1, WORD_TYPE_INT, NULL, ""},
    {(void *)0, {"007. dT8s5"              , "007. dT8s5"             , "007. dT8s5"             }, 806, 0, 16, 0, 1, WORD_TYPE_INT, NULL, ""},
    {(void *)0, {"008. Tao DHW Max"        , "008. Tao DHW Max"       , "008. Tao DHW Max"       }, 807, 0, 16, 0, 1, WORD_TYPE_INT, NULL, ""},
};

const uint16_t disp_ui_set_size = sizeof(disp_ui_set) / sizeof(disp_ui_set_t);
const uint16_t check0_ui_word_size = sizeof(check0_ui_word) / sizeof(disp_ui_word_t);
const uint16_t seting0_ui_word_size = sizeof(seting0_ui_word) / sizeof(disp_ui_word_t);

const sys_error_tab_t g_sys_error_tab[] = 
{
    {{"主控板EE故障",                "EE", "EE"}},//32_bit0 主控板EE故障
};

const uint16_t sys_error_tab_size = sizeof(g_sys_error_tab)/sizeof(g_sys_error_tab[0]);


//判断数据是什么类型，按特定样式表现(参数：类型、返回的载体、值)
char *fun_draw_ui_word(const disp_ui_word_t *disp_ui_word, char *pString, uint16_t reg_value)
{
    switch (disp_ui_word->type)
    {
        case WORD_TYPE_INT:
            pString += sprintf(pString, "%d",(int16_t)reg_value );
            break;
        case WORD_TYPE_SENSOR:
            pString += sprintf(pString, "%.1f", g_UserSet.Test_TEMP);
            break;
        case WORD_TYPE_UINT:
            pString += sprintf(pString, "%d",(uint16_t)reg_value );
            break;
        case WORD_TYPE_HEX:
            pString += sprintf(pString, "0x%04X", (uint16_t)reg_value);
            break;
        case WORD_TYPE_BIN:
            pString += sprintf(pString, "%x", reg_value);
            break;
        case WORD_TYPE_BCD:
            pString += sprintf(pString, "%x", reg_value);
            break;
        case WORD_TYPE_ENUM:
        case WORD_TYPE_ENUM2:
            if((int16_t)reg_value < 0){
                reg_value = 1;
            }
            reg_value = reg_value % 2;
            pString += sprintf(pString, "%s", disp_ui_word->_enum[reg_value ? 1 : 0].name[g_UserSet.Lauguage]);
            break;
        case WORD_TYPE_ENUM3:
            if((int16_t)reg_value < 0){
                reg_value = 2;
            }
            reg_value = reg_value % 3;
            pString += sprintf(pString, "%s", disp_ui_word->_enum[reg_value].name[g_UserSet.Lauguage]);
            break;
        case WORD_TYPE_ENUM4:
            if((int16_t)reg_value < 0){
                reg_value = 3;
            }
            reg_value = reg_value % 4;
            pString += sprintf(pString, "%s", disp_ui_word->_enum[reg_value].name[g_UserSet.Lauguage]);
            break;
        case WORD_TYPE_MACH:
            if((reg_value >= 0x80) && (reg_value <= 0x82)){
                reg_value = reg_value - 0x80;
            }else{
                reg_value = 3;
            }
            pString += sprintf(pString, "%s", disp_ui_word->_enum[reg_value].name[g_UserSet.Lauguage]);
            break;
        case WORD_TYPE_ENUM5:
            if((int16_t)reg_value < 0){
                reg_value = 4;
            }
            reg_value = reg_value % 5;
            pString += sprintf(pString, "%s", disp_ui_word->_enum[reg_value].name[g_UserSet.Lauguage]);
            break;
        case WORD_TYPE_ENUM6:
            if((int16_t)reg_value < 0){
                reg_value = 5;
            }
            reg_value = reg_value % 6;
            pString += sprintf(pString, "%s", disp_ui_word->_enum[reg_value].name[g_UserSet.Lauguage]);
            break;
        case WORD_TYPE_ENUM7:
            if((int16_t)reg_value < 0){
                reg_value = 6;
            }
            reg_value = reg_value % 7;
            pString += sprintf(pString, "%s", disp_ui_word->_enum[reg_value].name[g_UserSet.Lauguage]);
            break;
        case WORD_TYPE_ENUM9:
            if((int16_t)reg_value < 0){
                reg_value = 5;
            }
            reg_value = reg_value % 9;
            pString += sprintf(pString, "%s", disp_ui_word->_enum[reg_value].name[g_UserSet.Lauguage]);
            break;
        case WORD_TYPE_ADD15:
            pString += sprintf(pString, "%d",(int)reg_value - 15);
            break;
        case WORD_TYPE_MUL2:
            if((reg_value & 0xFF) == 0xFF){
                pString += sprintf(pString, "--");
            }else{
                pString += sprintf(pString, "%.1f",(float)((int16_t)reg_value)/2);
            }
            break;
        case WORD_TYPE_MUL2_ADD50:
            if((reg_value & 0xFF) == 0xFF){
                pString += sprintf(pString, "--");
            }else{
                pString += sprintf(pString, "%.1f",(float)((int16_t)reg_value - 50)/2);
            }
            break;
        case WORD_TYPE_MUL2_ADD60:
            if((reg_value & 0xFF) == 0xFF){
                pString += sprintf(pString, "--");
            }else{
                pString += sprintf(pString, "%.1f",(float)((int16_t)reg_value - 60)/2);
            }
            break;
        case WORD_TYPE_MUL10:
            pString += sprintf(pString, "%.1f",(float)((int16_t)reg_value)/10.0);
            break;
        case WORD_TYPE_MUL100:
            pString += sprintf(pString, "%.2f",(float)(int16_t)reg_value/100.0);
            break;
        case WORD_TYPE_MUL10_ADD300:
            pString += sprintf(pString, "%.1f",((float)reg_value - 300)/10.0);
            break;
        case WORD_TYPE_ADD40:
            pString += sprintf(pString, "%d",(int)reg_value - 40);
            break;
        case WORD_TYPE_ADD100:
            pString += sprintf(pString, "%d",(int)reg_value + 100);
            break;
        case WORD_TYPE_ADD5000:
            pString += sprintf(pString, "%d",(int)reg_value - 5000);
            break;
        case WORD_TYPE_DIV2:
            pString += sprintf(pString, "%d",reg_value*2);
            break;
        case WORD_TYPE_DIV6:
            pString += sprintf(pString, "%d",reg_value*6);
            break;
        case WORD_TYPE_DIV10:
            pString += sprintf(pString, "%d",reg_value*10);
            break;
        case WORD_TYPE_DIV100:
            pString += sprintf(pString, "%d",reg_value*100);
            break;
        case WORD_TYPE_DIV15:
            pString += sprintf(pString, "%d",reg_value*15);
            break;
        case WORD_TYPE_ERRCODE:
            if(!reg_value){
                pString += sprintf(pString, "%s","--");
            }else{
                pString += sprintf(pString, "%02X", reg_value);
            }
            break;

        case WORD_TYPE_MODE:
            pString += sprintf(pString, "%s", string_mode_enum[g_UserSet.Lauguage][g_UserSet.Mode]);
            break;

        case WORD_TYPE_TEMP:
            if((int16_t)reg_value == -500){
                pString += sprintf(pString, "--");
            }else{
                pString += sprintf(pString, "%.1f",(float)((int16_t)reg_value)/10.0);
            }
            break;

        case WORD_TYPE_DVER:
            pString += sprintf(pString, "V%02d", 0); 
            break;

        case WORD_TYPE_DVER2:
            pString += sprintf(pString, "%s %s", __DATE__, __TIME__); 
            break;

        case WORD_TYPE_REV:
            pString += sprintf(pString, "%d", 0);
            break;

        default:
            pString += sprintf(pString, "%d",(int)reg_value );
            break;

    }
    if(disp_ui_word->unit){
        pString += sprintf(pString, " %s", disp_ui_word->unit);
    }
    return pString;
}